package com.wanli.agent.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.wanli.agent.R;
import com.wanli.agent.bean.BusinessProviderOrMerchantInfoBean;
import com.wanli.agent.bean.UserInfoBean;
import com.wanli.agent.utils.SPManager;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 服务商、商户信息列表
 */
public class ProviderOrMerchantDataListAdapter extends RecyclerView.Adapter<ProviderOrMerchantDataListAdapter.ViewHolder> {

    private List<BusinessProviderOrMerchantInfoBean.DataBean> listsBeans;
    private Context context;
    private UserInfoBean userInfoBean;
    private int roleFlag = 0;

    public ProviderOrMerchantDataListAdapter(List<BusinessProviderOrMerchantInfoBean.DataBean> listsBeans, int roleFlag) {
        this.listsBeans = listsBeans;
        this.roleFlag = roleFlag;
        userInfoBean = new Gson().fromJson(SPManager.getInstance().getUserInfoJson(), UserInfoBean.class);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_data_provider_merchant, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        BusinessProviderOrMerchantInfoBean.DataBean dataBean = listsBeans.get(position);
        holder.tvName.setText(dataBean.getName());
        holder.tvDealAmountTotal.setText(dataBean.getTrade_money());
        if (this.roleFlag == 0) {
            holder.tvTitle.setText("新增商户数");
            holder.tvValue.setText(dataBean.getAdd_merchant());
        } else {
            holder.tvTitle.setText("交易笔数");
            holder.tvValue.setText(dataBean.getOrder_free_all());
        }
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.ivHead)
        ImageView ivHead;
        @BindView(R.id.tvName)
        TextView tvName;
        @BindView(R.id.tvAmountTitle)
        TextView tvAmountTitle;
        @BindView(R.id.tvDealAmountTotal)
        TextView tvDealAmountTotal;
        @BindView(R.id.tvTitle)
        TextView tvTitle;
        @BindView(R.id.tvValue)
        TextView tvValue;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
